home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / apps / ibrowse / ibrowse_il.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.3 KB  |  181 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.     ibrowse_il.c - Support for identifying and iconifying ImageVision
  19.     Library image format files, including TIFF, FIT, and future additions.
  20.  
  21.     Tim Heidmann
  22.     Version 1.2.2
  23.     November 30, 1993
  24.     modified for IL 2.3 3/18/94
  25.  
  26.     copyright 1993, Silicon Graphics
  27. */
  28.  
  29. #include <il/ilGenericImgFile.h>
  30. #include <il/ilCdefs.h>
  31. #include <stdio.h>
  32. #include <stdlib.h> /* getenv() */
  33. #include <string.h> /* strcmp() */
  34. #include "ibrowse.h"
  35.  
  36. int unThreaded = FALSE;
  37.  
  38.  
  39. int
  40. Check_IL(struct iconDirStruct *ids, int fd) {
  41.     /* Check for IL image type file.
  42.        If it is an IL image, set xsize, ysize, zsize.
  43.        Return TRUE iff it is an IL format image file. */
  44.     char name_buf[PATH_MAX];
  45.     ilFileImg *theIlFile;
  46.     char *typeName;
  47.  
  48.     if (strcmp(ids->name, "..") == 0) return FALSE;
  49.     if (strcmp(ids->name, ".") == 0) return FALSE;
  50.  
  51.     /* Defeat multi-threading, which interferes with our UI/reader operation */
  52. if (!unThreaded) {
  53. /* Not in libcil.a yet...
  54.     ilMpSetMaxProcs(0, 0);
  55. */
  56. putenv("IL_COMPUTE_THREADS=0");
  57. putenv("IL_SPARE_THREADS=0");
  58.     unThreaded = TRUE;
  59. }
  60.  
  61.     sprintf(name_buf, "%s/%s", theDirName, ids->name);
  62.     theIlFile = ilOpenImgFile(name_buf, "r");
  63.     if (theIlFile != NULL) {
  64.     ids->xsize   = ilGetXsize((ilImage *) theIlFile);
  65.     ids->ysize   = ilGetYsize((ilImage *) theIlFile);
  66.     ids->zsize   = ilGetCsize((ilImage *) theIlFile);
  67.  
  68.     /* In IL2.3, get format returns a char * rather than an int */
  69.     typeName = ilFileImgGetImageFormat(theIlFile);
  70.     if      (strcmp(typeName, ilFIT_IMG)  == 0)    ids->subType = 1;
  71.     else if (strcmp(typeName, ilTIFF_IMG) == 0)    ids->subType = 2;
  72.     else if (strcmp(typeName, ilSGI_IMG)  == 0)    ids->subType = 3;
  73.     else                                           ids->subType = 0;
  74.  
  75.     ilImageDelete((ilImage *) theIlFile);
  76.     return TRUE;
  77.  
  78.     } else
  79.     return FALSE;
  80. }
  81.  
  82. /*
  83.  * Read image file and subsample into memory slot.
  84.  */
  85.  
  86. /* Keep these for a while in case we need them... */
  87. #define PACK_RGBA_08(r, g, b, a) ((a)<<24 | (b)<<16 | (g)<<8 | (r))
  88. #define PACK_RGBA_16(r, g, b, a) (((a)&0xff00)<<16 | ((b)&0xff00)<<8 |  \
  89.     ((g)&0xff00) | ((r)&0xff00)>>8)
  90.  
  91. int
  92. Iconify_IL(struct iconDirStruct *ids, unsigned long *ip) {
  93.     char name_buf[PATH_MAX];
  94.     ilFileImg    *theIlFile;
  95.     ilRotZoomImg *theRZImg;
  96.     ilABGRImg *theABGR;
  97.     ilConfig     *theConfig;
  98.     int           returnCode;
  99.     static int theChanList[] = {0, 1, 2, 3};
  100.  
  101.     if (ids->xsize <= 0 || ids->ysize <= 0 || ids->zsize <= 0) return TRUE;
  102.  
  103.     /* Defeat multi-threading, which interferes with our UI/reader operation */
  104. if (!unThreaded) {
  105. /* Not in libcil.a yet...
  106.     ilMpSetMaxProcs(0, 0);
  107. */
  108. putenv("IL_COMPUTE_THREADS=0");
  109. putenv("IL_SPARE_THREADS=0");
  110.     unThreaded = TRUE;
  111. }
  112.  
  113.     /* Open the image file, describe the zoom down */
  114.     returnCode = TRUE;
  115.     sprintf(name_buf, "%s/%s", theDirName, ids->name);
  116.     if ((theIlFile = ilOpenImgFile(name_buf, "r")) == NULL) return FALSE;
  117.     theRZImg = ilRotZoomImgCreate((ilImage *) theIlFile, 0.0, 1.0, 1.0,
  118.     ilNoFlip, ilNearNb);
  119.     ilRotZoomImgSizeToFit(theRZImg, ids->ixsize, ids->iysize, FALSE);
  120.     theABGR = ilABGRImgCreate((ilImage *) theRZImg);
  121.  
  122.     /* Configure the icon pixels and get them */
  123.     theConfig = ilConfigCreate(ilUChar, ilInterleaved, 4, NULL, 0,
  124.     ilLowerLeftOrigin, (ilColorModel) 0);
  125.     if (
  126.     ilGetTile((ilImage *) theABGR, 0, 0, ids->ixsize, ids->iysize, ip,
  127.         theConfig)
  128.     != ilOKAY) returnCode = FALSE;
  129.  
  130.     ilConfigDelete(theConfig);
  131.     ilImageDelete((ilImage *) theABGR);
  132.     ilImageDelete((ilImage *) theRZImg);
  133.     ilImageDelete((ilImage *) theIlFile);
  134.     return returnCode;
  135. }
  136.  
  137.  
  138. char *
  139. Info_IL(struct iconDirStruct *ids, char *buf) {
  140.     int colormap;
  141.  
  142.     switch (ids->subType) {
  143.     case 1:  sprintf(buf, "FIT format image");         break;
  144.     case 2:  sprintf(buf, "TIFF format image");        break;
  145.     case 3:  sprintf(buf, "SGI format image");         break;
  146.     default: sprintf(buf, "ImageVision format image"); break;
  147.     }
  148.  
  149.     return buf;
  150. }
  151.  
  152. void
  153. Open_IL(struct iconDirStruct *ids) {
  154.     char buf[PATH_MAX+64];
  155.     char *cmd;
  156.  
  157.     /* Defeat multi-threading, which interferes with our UI/reader operation */
  158. if (!unThreaded) {
  159. /* Not in libcil.a yet...
  160.     ilMpSetMaxProcs(0, 0);
  161. */
  162. putenv("IL_COMPUTE_THREADS=0");
  163. putenv("IL_SPARE_THREADS=0");
  164.     unThreaded = TRUE;
  165. }
  166.  
  167.     /* What to do on double-click of icon - Execute env var or imgview! */
  168.     if ((cmd = getenv("IBROWSE_IL_OPEN_CMD")) != NULL)
  169.     /* Execute contents of Environment variable */
  170.     ;
  171.  
  172.     else if (useIconFiles)
  173.     /* Browsing from icon files.  Don't try to open an image file. */
  174.     return;
  175.  
  176.     else
  177.     sprintf(cmd = buf, "/usr/sbin/imgview %s/%s &", theDirName, ids->name);
  178.  
  179.     system(cmd);
  180. }
  181.